Bitmask-Enum
A bitmask enum attribute macro, to turn an enum into a bitmask.
A bitmask can have unsigned integer types, the default type is usize
.
Don't know how to document in proc-macro
crates so if you want to see a better documentation, run cargo doc --open
and select your #[bitmask]
enum.
// usize
// u8
Example
use bitmask;
// bitmask has const bitwise operator methods
const CONST_BM: Bitmask = Flag2.or;
println!; // 0b00000110
// Bitmask that contains Flag1 and Flag3
let bm = Flag1 | Flag3;
println!; // 0b00000101
// Does bm intersect one of CONST_BM
println!; // true
// Does bm contain all of CONST_BM
println!; // false
Custom Values
You can assign every flag a custom value.
Because behind the scences enum Bitmask
gets converted to a struct Bitmask(u8);
you need to wrap u8
expressions into a Self(_)
.
use bitmask;
let bm = Flag1 | Flag3;
println!; // 0b00010001
println!; // true
println!; // true
println!; // 0b00010101